﻿using OF.Component.BLL;
using OF.Component.Model;
using OF.Utility;
using OpSystem.common;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OF.Security;

namespace OpSystem
{
    public partial class Home : BasePage
    {
        protected string menuli = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetMenuList();
            }
        }

        protected void SetMenuList()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("[");
            //var menuList = AuthorityRoleMenuRelaOperate.GetRoleMenuList(CurrentUser.UserId, SystemCode).OrderBy(a=>a.OrderNum);
            var menuList = AuthorityRoleMenuRelaOperate.GetRoleMenuList(UserContext.Current.UserID, SystemCode).OrderBy(a => a.OrderNum);
            foreach (AuthorityMenuInfo item in menuList.Where(a => a.ParentID == 0))
            {
                sb.Append("{");
                sb.AppendFormat(" id: \"{0}\", text: \"{1}\", icon: \"fa fa-laptop\"",item.MenuCode, item.MenuName);
                sb.Append(",children:[");
                int j = 0;
                foreach (var chlidItem in menuList.Where(a => a.ParentID == item.MenuID))
                {
                    if (j != 0)
                    {
                        sb.Append(",");
                    }
                    sb.Append("{");
                    sb.AppendFormat("id: \"{0}\", text: \"{1}\", icon: \"fa fa-circle-o\", url: \"{2}\",targetType: \"iframe\"", chlidItem.MenuCode, chlidItem.MenuName, chlidItem.MenuUrl);
                    sb.Append("}");
                    j++;
                }
                sb.Append("]},");
            }
            sb.Append("]");
            menuli = sb.ToString().TrimEnd(',');
        }
    }
}